<%--
功能：商品图片
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="product" tagdir="/WEB-INF/tags/product"%>
<%@ tag import="org.springframework.context.ApplicationContext" %>
<%@ tag import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ tag import="com.probiz.estore.product.service.ProductManager" %>
<%@ tag import="com.probiz.estore.common.model.product.Product" %>
<%@ tag import="org.apache.commons.lang.StringUtils;" %>
<%@ attribute name="product" type="com.probiz.estore.common.model.product.Product" required="false" description="商品"%>
<%@ attribute name="productId" type="java.lang.Integer" required="false" description="商品id 如果product 无指定,则可用这个"%>
<%@ attribute name="productCode" type="java.lang.String" required="false" description="商品code.如果product,productId无指定，则必须指定productCode" %>
<%@ attribute name="linkType" type="java.lang.Short"  description="0表示没有链接，1表示链接去商品页，2表示打开新窗口查看原图，不填表示1"%>
<%@ attribute name="sizeType" type="java.lang.String" description="s0=(58X58) s1=(115X115); s2=(170X170); m0=(370X370); (s代表小，m代表中)不填代表显示的是原图，尺寸不限" %>
<%@ attribute name="target" %>
<%@ attribute name="width" %>
<%@ attribute name="height" %>
<%@ attribute name="style" %>
<%@ attribute name="linkClass" %>
<%@ attribute name="id" %>
<%@ attribute name="alt" %>
<%@ attribute name="onmouseover" %>
<%@ attribute name="onclick" %>
<c:if test="${empty target}">
	<c:set var="target" value="_blank" scope="request"/>
</c:if>
<%
	ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
	ProductManager productManager = (ProductManager) ctx.getBean("productManager");
	Product targetProduct = product;
	if(null == targetProduct){
		if(null != productId){
			targetProduct = productManager.getById(productId);
		}else if(null != productCode){
			targetProduct = productManager.getProductByProductCode(productCode);
		}else{
			//构造一个虚拟product
			targetProduct = new Product();
		}
	}	
	request.setAttribute("targetProduct",targetProduct);
	
	String url = targetProduct.getImageUrl();
	if(StringUtils.isNotBlank(url)){
		if(StringUtils.isNotBlank(sizeType)){
			int index = url.lastIndexOf(".");
			if(index!=-1)url = url.substring(0, index) + "_"+sizeType + url.substring(index);
		}
		jspContext.setAttribute("imageUrl",session.getAttribute("mediaPath")+url);
		jspContext.setAttribute("linkImageUrl",targetProduct.getImageUrl());
	}else{
		if(StringUtils.isNotBlank(sizeType)){
			jspContext.setAttribute("imageUrl",session.getAttribute("imagePath")+"/default/defaultNoPhoto_"+sizeType+".jpg");
		}else{
			jspContext.setAttribute("imageUrl",session.getAttribute("imagePath")+"/default/defaultNoPhoto.jpg");
		}		
		jspContext.setAttribute("linkImageUrl","");
	}	
%>
<c:choose>
	<c:when test="${linkType==0}">
	</c:when>
	<c:when test="${empty linkType or linkType==1}">
		<a title="${targetProduct.productName}"  href="<product:productUrl product="${targetProduct}"/>" <c:if test="${not empty linkClass}">class="${linkClass}"</c:if> <c:if test="${not empty target}">target="${target}"</c:if>> 
	</c:when>
	<c:when test="${linkType==2}">
		<c:choose>
			<c:when test="${not empty linkImageUrl}">
				<a href="${mediaPath}${linkImageUrl}" target="blank">
			</c:when>
			<c:otherwise>
				<a href="javascript:void(0);"><!--重要：上传图后要把a的target设为_blank  -->
			</c:otherwise>
		</c:choose>
		
	</c:when>
</c:choose>
<img src="${imageUrl}" onerror="$j(this).attr('originsrc',this.src);this.src=__defaultImage${(not empty sizeType)?'_':''}${sizeType};this.onerror='';" originsrc=""
alt="${targetProduct.productName}"
title="${targetProduct.productName}"
<c:if test="${not empty width}">width="${width}"</c:if>
<c:if test="${not empty height}">height="${height}"</c:if>
<c:if test="${not empty style}">style="${style}"</c:if>
<c:if test="${not empty id}">id="${id}"</c:if>
<c:if test="${not empty alt}">alt="${alt}"</c:if>
<c:if test="${not empty onmouseover}">onmouseover="${onmouseover}" </c:if>
<c:if test="${not empty onclick}">onclick="${onclick}" </c:if> />
<c:if test="${empty linkType or linkType!=0}"></a></c:if>




